package me.youline.dataServer.service.account;

import java.io.InputStream;

import me.youline.dataServer.entity.UserBaseInfo;
import me.youline.dataServer.entity.UserBaseInfo.From;
import me.youline.dataServer.entity.UserBaseInfo.Gender;
import me.youline.dataServer.entity.UserSocialConnect.ConnectType;

import org.springframework.util.Assert;

/**
 * 用户个人信息操作实体
 * @author linhan
 *
 */
public class UserProfileOperationInfo {

	private final UserBaseInfo baseInfo;

	private final InputStream avatarFile;

	public UserProfileOperationInfo(UserBaseInfo info, InputStream avatarFile) {
		Assert.notNull(info);
		this.baseInfo = info;
		this.avatarFile = avatarFile;
	}

	public UserBaseInfo getBaseInfo() {
		return baseInfo;
	}

	public InputStream getAvatarFile() {
		return avatarFile;
	}

	public static class UserProfileUpdateInfo extends UserProfileOperationInfo {

		private final Long userId;

		public UserProfileUpdateInfo(Long userId, UserBaseInfo info,
				InputStream avatarFile) {
			super(info, avatarFile);
			Assert.notNull(userId);
			this.userId = userId;
		}

		public Long getUserId() {
			return userId;
		}
	}

	/**
	 * 用户信息添加实体，它只是抽象定义了一个用户需要用户名和密码基本信息
	 * 
	 * @author linhan
	 *
	 */
	public static abstract class UserProfileAddInfo extends UserProfileOperationInfo {

		private final String userName;

		private final String password;

		public UserProfileAddInfo(String userName, String password,
				UserBaseInfo info, InputStream avatarFile) {
			super(info, avatarFile);
			Assert.notNull(userName);
			Assert.notNull(password);
			this.userName = userName;
			this.password = password;
			info.setPhoneNum(userName);
			if(info.getGender() == null){
				info.setGender(Gender.MALE);
			}
		}

		public String getUserName() {
			return userName;
		}

		public String getPassword() {
			return password;
		}

	}

	/**
	 * 从第三方平台账号关联的用户数据添加实体
	 * @author linhan
	 *
	 */
	public static class UserProfileSocialAddInfo extends UserProfileAddInfo {

		private final String socialConnectId;

		private final ConnectType connectType;

		public UserProfileSocialAddInfo(String userName,String password, UserBaseInfo info, InputStream avatarFile, String socialConnectId,ConnectType connectType ) {
			super(userName, password,info,avatarFile);
			Assert.notNull(socialConnectId);
			Assert.notNull(connectType);
			this.socialConnectId = socialConnectId;
			this.connectType = connectType;
			info.setCreatedFrom(From.THIRD_PART);
		} 

		public String getSocialConnectId() {
			return socialConnectId;
		}

		public ConnectType getConnectType() {
			return connectType;
		}
		
	}

	/**
	 * 用户数据普通方式添加实体，它代表用户从手机app端直接注册的数据
	 * @author linhan
	 *
	 */
	public static class UserProfileGeneralAddInfo extends
			UserProfileAddInfo {

		public UserProfileGeneralAddInfo(String userName, String password,
				UserBaseInfo info, InputStream avatarFile) {
			super(userName, password, info, avatarFile);
			info.setCreatedFrom(From.APP_REGISTER);
		}
	}

}
